<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: pending.class.php 87081 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
  defined('PHPFOX') or exit('NO DICE!');
  class Follow_Component_Controller_Pending extends Phpfox_Component
  {
      public function process()
      {
          Phpfox::isUser(true);
		  $categories = Phpfox::getService('marketplace.category')->getForBrowse();
			foreach($categories as $key=>$cat){
				reset($arrEx);
				$endName = '';
				$arrEx = array();
				if($cat['name'][0]=='{'){
					$arrEx = explode("var=",$cat['name']);
					$endName = substr($arrEx[1], 6, -7);
					$categories[$key]['name'] = Phpfox::getPhrase($endName);
				}
			}
			$this->template()->assign(array(
						'categories' => $categories)
			);
          $oProcess = Phpfox::getService('follow.process');
          $aSetting = $oProcess->getSetting(Phpfox::getUserId());
          
          $this->search()->set(array(
                'type' => 'follow',
                'field' => 'follow.user_id',                
                'search_tool' => array(
                    'table_alias' => 'follow',
                    'search' => array(
                        'action' => '',
                        'default_value' => Phpfox::getPhrase('follow.search_pending_dot'),
                        'name' => 'search',
                        'field' => array('follow.user_id', 'follow.item_id')
                    ),
                    'sort' => array(
                        'latest' => array('follow.time_stamp',Phpfox::getPhrase('follow.lastest')),
                    ),
                    'show' => array(5, 10, 15),
                )
        ));
        $aBrowseParams = array(
            'module_id' => 'follow',
            'alias' => 'follow',
            'field' => 'user_id',
            'table' => Phpfox::getT('follow_pending')
        );
        
        $aSetting = Phpfox::getService('follow.process')->getSetting(Phpfox::getUserId());
        $sKeyword = ($this->search()->get('search')) ? $this->search()->get('search') : '';
        $iAmount = ($this->request()->getInt('show'))? $this->request()->get('show'): 5;
        $iOffset = ($this->request()->getInt('page') >= 2)?($this->request()->getInt('page') - 1)*$iAmount:0;
        list($iCnt, $aItems) = Phpfox::getService('follow')->getPending($sKeyword, Phpfox::getUserId(), $iOffset, $iAmount);
        
        Phpfox::getLib('pager')->set(array('page' => $this->search()->getPage(),
         'size' => $this->search()->getDisplay(), 'count' => isset($iCnt)? $iCnt: 0));
         
         $this->template()->setHeader(array(
            'jquery/ui.js' => 'static_script',
            'follow.js' => 'module_follow',
            '<script type="text/javascript">$Core.follow.url(\'' . $this->url()->makeUrl('follow') . '\');</script>',
         ));
         
         $this->template()->setHeader('cache', array(
            'jquery/plugin/jquery.highlightFade.js' => 'static_script',
            'jquery/plugin/jquery.scrollTo.js' => 'static_script',
            'quick_edit.js' => 'static_script',
            'comment.css' => 'style_css',
            'pager.css' => 'style_css',
            'feed.js' => 'module_follow',
            'friend.js' => 'module_friend',
            'friend.css' => 'style_css',
            'follow.css' => 'module_follow'
                )
         )->assign(array(
            'aItems' => $aItems,
            'aSetting' => $aSetting,
            'sType' => 'user',
            'iCurrUserId' => Phpfox::getUserId()
         )); 
      }
  }
?>
